package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingLevelController
 * @Author LiShunSen
 * @Date 2024-08-28
 */
@RestController
@Slf4j
@Api(tags = "护理等级相关接口")
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级
     *
     * @return
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> geiAll() {
        List<NursingLevelVo> nursingLevelVo = nursingLevelService.getAll();
        return success(nursingLevelVo);
    }

    /**
     * 新增
     *
     * @param nursingLevelDto
     * @return
     */
    @ApiOperation("新增")
    @PostMapping("/insert")
    public ResponseResult insertLevel(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.insertLevel(nursingLevelDto);
        return success();
    }

    /**
     * 分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态:0-禁用,1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {

        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.getByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingLevelVo> getId(@PathVariable("id") Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getId(id);
        return success(nursingLevelVo);
    }

    /**
     * 修改
     *
     * @param nursingLevelDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改")
    public ResponseResult updateLevel(
            @ApiParam(value = "修改的实体类")
            @RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.updateLevel(nursingLevelDto);
        return success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public ResponseResult deleteLevel(@PathVariable("id") Long id) {
        nursingLevelService.deleteLevel(id);
        return success();
    }

    /*
     * 启用/禁用护理计划
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用")
    public ResponseResult statusLevel(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        nursingLevelService.statusLevel(id, status);
        return success();
    }
}
